/**
 * Copyright (c) 2015-2030 by Beijing Yanlight Co., Ltd.
 * All rights reserved.
 */
package com.yanlight.util;

import java.util.Map;
import java.util.Map.Entry;

/**
 * 
 * @author haolw
 * @time 2017/07/20
 */
public abstract class MapUtil {

	/**
	 * {"a":"1","b":"2"}-->a=1&b=2
	 * 
	 * @param paramsMap
	 * @return
	 */
	public static String toUrlParams(Map<String, String> paramsMap) {
		if (paramsMap == null || paramsMap.isEmpty()) {
			return "";
		} else {
			StringBuilder paramsBuilder = new StringBuilder(16);
			for (Entry<String, String> entry : paramsMap.entrySet()) {
				paramsBuilder.append("&");
				paramsBuilder.append(entry.getKey());
				paramsBuilder.append("=");
				paramsBuilder.append(entry.getValue());
			}
			return paramsBuilder.substring(1);
		}
	}
}
